-
Notifications
You must be signed in to change notification settings - Fork 9
Add min/max file size limits by mime type. #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Appreciate the PR, will consider for v5 |
if (mimeMaxFileSizes !== null) { | ||
Object.keys(mimeMaxFileSizes).forEach(mime => { | ||
if (file.type === mime || | ||
(mime.substring(2, -2) === '/*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(mime.substring(2, -2) === '/*' | |
(mime.substring(mime.length-2) === '/*' |
if (mimeMinFileSizes !== null) { | ||
Object.keys(mimeMinFileSizes).forEach(mime => { | ||
if (file.type === mime || | ||
(mime.substring(2, -2) === '/*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(mime.substring(2, -2) === '/*' | |
(mime.substring(mime.length-2) === '/*' |
|
||
// Max individual file size in bytes | ||
maxFileSize: [null, Type.INT], | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Multipliers should probably be 1024 vs 1000, | ||
// but this mimics the internal behavior. | ||
const multiplier = { b: 1, kb: 1000, mb: 1000**2, gb: 1000**3, tb: 1000**4, pb: 1000**5 } | ||
const num = Number(str.match(/\d/).toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const num = Number(str.match(/\d/).toString()) | |
const num = Number(str.match(/\d+/).toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works better for values like 1024KB
. For example, see the different max sizes in https://community.sinch.com/t5/MMS/What-is-the-maximum-size-of-MMS-message-that-you-can-send/ta-p/7847
Closes issue #3.
Adds optional
mimeMinFileSizes
andmimeMaxFileSizes
config options, these should work in conjunction with existing min/max and max total limits, and allow for setting min or max limits by explicit mime type or mime type wildcard group:ie:
That config will allow images of any type up to 3mb, but allow gifs to be up to 5mb, and restrict mp4 videos to 100MB.